package cn.ailanyin.home.module.file.controller;

import cn.ailanyin.home.common.entity.Result;
import cn.ailanyin.home.constant.BaseConstant;
import cn.ailanyin.home.module.file.utils.FileUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件
 *
 * @author ailanyin
 * @date 2024-04-19 17:15:44
 */
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
@Tag(name = "文件管理")
public class FileController {

    @Value("${file.uploadPath:}")
    private String uploadPath;

    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    public Result upload(MultipartFile file) {
        String path = FileUtil.upload(file, uploadPath);
        return Result.success(BaseConstant.RESOURCE_PREFIX + "/" + path);
    }
}
